package com.liang.text;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.net.Socket;

public class AcceptMsg extends Thread{

    private Socket socket;

    public AcceptMsg(Socket socket) {
        this.socket = socket;
    }

    @Override
    public void run() {
        try {

            InputStream is = socket.getInputStream();
            BufferedReader bw = new BufferedReader(new InputStreamReader(is));

            String str;
            while ((str = bw.readLine()) != null) {
                System.out.println(socket.getLocalAddress()+":  "+str);
                if (str.equals("再见")) {
                    socket.shutdownInput();
                }
            }
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}
